import os

def generate_markdown(root_dir, output_file):
  """
  将 Vue 项目文件合并成 Markdown 文件, 忽略 node_modules 和 . 开头的文件
  Args:
    root_dir: Vue 项目根目录
    output_file: 输出 Markdown 文件路径
  """
  with open(output_file, 'w', encoding='utf-8') as f:
    for dirpath, dirnames, filenames in os.walk(root_dir):
      # 跳过 node_modules 文件夹
      if 'node_modules' in dirnames:
        dirnames.remove('node_modules')
      
      for filename in filenames:

        if filename.endswith(('.ts', '.js', '.vue')):
          file_path = os.path.join(dirpath, filename)
          rel_path = os.path.relpath(file_path, root_dir)
          with open(file_path, 'r', encoding='utf-8') as code_file:
            code = code_file.read()
            f.write(f"## {filename} [{rel_path}]\n")
            f.write("```\n")
            f.write(code)
            f.write("\n```\n\n")

# 使用示例
root_dir = r'E:\wkai\vue-element-plus-admin'  # 修改为你的项目目录
output_file = 'vue-element-plus-admin.md'
generate_markdown(root_dir, output_file)

print(f"代码已合并到 {output_file}")